import { ref, reactive } from "vue";

interface mediaOption {
    mainType: number;
    ifCompanyAndOrgGroup?: number;
    uperId?: number;
    ifHadBuy?: number;
    aiAnalysisStatus?: number;
    ifChildMediaResource?: number;
    ifConfirmRight?: number;
    listType?: number;
    columns?: string | number | any;
    column?: string | number;
    start?: string;
    end?: string;
    ifTimeDesc?: boolean;
    lastId?: any;
    status?: number;
    ifFolderTop?: boolean;
    folder_id?: string;
    goodsStatus?:string | number
}

interface BreadCrumb {
    title: string;
    file_id?: number | string | null;
    media_resource_id?: number | string | null;
}

interface senType {
    file_id?: string | number;
    folder_id?: string;
    new_name?: string;
    location?: number;
    is_media?: number;
    files?: [];
    target_id?: string | number;
    name?: string;
    if_merge?: string | boolean;
}

// 公司媒资
const searchOption_company: mediaOption = {
    listType: 1,
    mainType: 0,
    // uperId:0,
    aiAnalysisStatus: 0,
    columns: "",
    ifTimeDesc: true,
    ifChildMediaResource: 0, //类型
    ifCompanyAndOrgGroup: 0, //权限
    start: "",
    end: "",
    lastId: "",
    ifHadBuy: 0,
    status: 0,
    ifFolderTop: true,
    folder_id: "0",
    goodsStatus:''
};

// 购买媒资
const searchOption_buy: mediaOption = {
    listType: 1,
    mainType: 0,
    aiAnalysisStatus: 0,
    ifTimeDesc: true,
    start: "",
    end: "",
    lastId: "",
    ifHadBuy: 2,
    status: 2,
};







// 我的媒资
const searchOption_my: mediaOption = {
    ifConfirmRight: 0,
    listType: 2,
    mainType: 0,
    // uperId:0,
    aiAnalysisStatus: 0,
    column: 0,
    ifTimeDesc: true,
    ifChildMediaResource: 0, //类型
    start: "",
    end: "",
    lastId: "",
    status: 0,
    ifHadBuy: 0,
};

// 回收站
const searchOption_recycle: mediaOption = {
    listType: 3,
    mainType: 0,
    lastId: "",
    status: -1,
};

const mainTypeOptionFn = (id: number) => {
    let text: string = "";
    switch (id) {
        case 1:
            text = "图片";
            break;
        case 2:
            text = "视频";
            break;
        case 3:
            text = "音频";
            break;
        case 4:
            text = "文档";
            break;
        case 5:
            text = "文稿";
            break;
        case 6:
            text = "其它";
            break;
        case 0:
            text = "全部";
            break;
        case -1:
            text = "文件夹";
            break;
    }
    return text;
};

const mainTypeOptionIdFn = (text: string) => {
    // console.log(text)
    let id: any;
    switch (text) {
        case "图片":
            id = 1;
            break;
        case "视频":
            id = 2;
            break;
        case "音频":
            id = 3;
            break;
        case "文档":
            id = 4;
            break;
        case "其它":
            id = 6;
            break;
        case "all":
            id = 0;
            break;
        case "文件夹":
            id = -1;
            break;
    }
    return id;
};

// 时间戳互转
const timestampToTimeFn = (timestamp: number) => {
    let date = new Date(timestamp);
    let Y = date.getFullYear();
    let M =
        date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
    let D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let H = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    let Min =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    let S =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

    return `${Y}-${M}-${D} ${H}:${Min}:${S}`;
};

const toTimestampFn = (timestamp: number) => {
    let date = new Date(timestamp).getTime();
    return date;
};
const toTimestampStartFn = (timestamp: number) => {
    let date = new Date(new Date(timestamp).toLocaleDateString()).getTime();
    return date;
};

const toTimestampEndFn = (timestamp: number) => {
    let date = new Date(
        new Date(timestamp).getTime() + 24 * 60 * 60 * 1000 - 1
    ).getTime();
    return date;
};

// 筛选条件 上传人  媒资类型  权限 栏目
const filterObj = reactive({
    ifDesc: {
        name: "排序",
        val: [
            { name: "时间倒序", id: "true" },
            { name: "时间正序", id: "false" },
        ],
        activeId: "true",
    },
    // aiAnalysisStatus: {
    //     name: "AI分析",
    //     val: [
    //         { name: "全部", id: "0" },
    //         { name: "已分析", id: "2" },
    //         { name: "未分析", id: "1" },
    //     ],
    //     activeId: "0",
    // },
    // ifChildMediaResource: {
    //     name: "媒资类型",
    //     val: [
    //         { name: "全部", id: "0" },
    //         { name: "主媒资", id: "1" },
    //         { name: "子媒资", id: "2" },
    //     ],
    //     activeId: "0",
    //     tabType: "1",
    // },
    ifCompanyAndOrgGroup: {
        name: "权限",
        val: [
            { name: "全部", id: "0" },
            { name: "公司私有", id: "1" },
            { name: "传媒联盟", id: "2" },
        ],
        activeId: "0",
        tabType: "1",
    },
    // ifConfirmRight: {
    //     name: "媒确权",
    //     val: [
    //         { name: "全部", id: "0" },
    //         { name: "已确权", id: "1" },
    //         { name: "未确权", id: "2" },
    //     ],
    //     activeId: "0",
    //     tabType: "1",
    //     type: "my",
    // },
    status: {
        name: "审核状态",
        val: [
            { name: "全部", id: "0" },
            { name: "已过审", id: "2" },
            { name: "审核中", id: "1" },
            { name: "被拒绝", id: "3" },
        ],
        activeId: "0",
        tabType: "1",
    },
    // source: {
    //     name: "来源",
    //     val: [
    //         { name: "全部", id: "" },
    //         { name: "公司自有", id: "zy" },
    //         { name: "摄图网", id: "2" },
    //     ],
    //     activeId: "",
    //     tabType: "1",
    // },

    goodsStatus: {
        name: "交易状态",
        val: [
            { name: "全部", id: "-1" },
            { name: "未发布", id: "0" },
            { name: "在售中", id: "1" },
            { name: "已下架", id: "2" },
            { name: "审核中", id: "3" },
            { name: "未通过", id: "4" },
            // { name: "上传中", id: "100" },
            // { name: "不可操作", id: "110" },
            { name: "退回", id: "10" },
        ],
        activeId: "",
        tabType: "1",
    },

    columns: {
        name: "栏目",
        val: [{ name: "全栏目", id: "" }],
        activeId: "",
        tabType: "1",
    },
});

const timeArr = [
    { name: "全部", val: "" },
    { name: "近一周", val: "近一周" },
    { name: "近一月", val: "近一月" },
    { name: "近三月", val: "近三月" },
    { name: "近六月", val: "近六月" },
    { name: "近一年", val: "近一年" },
    { name: "近三年", val: "近三" },
];

// 移动
const handleRemove = (e: any, doc: any) => {
    console.log(e);
    let dom: any = document.getElementsByClassName(doc)[0];
    // 鼠标的位置
    let x = e.clientX;
    let y = e.clientY;
    // 元素的大小
    let domW = dom.offsetWidth;
    let domH = dom.offsetHeight;

    // 元素的位置
    let domLeft = dom.offsetLeft;
    let domTop = dom.offsetTop;

    // 窗口大小
    let w = window.innerWidth;
    let h = window.innerHeight;

    // 鼠标到元素左边距离
    let moveX = x - domLeft;
    let moveY = y - domTop;
    document.onmousemove = function (e) {
        let dropX = w - (e.clientX - moveX) - domW;
        let dropY = h - (e.clientY - moveY) - domH;

        if (dropX > w - domW) {
            dropX = w - domW;
        } else if (dropX < 0) {
            dropX = 0;
        }
        if (dropY > h - domH - 10) {
            dropY = h - domH - 10;
        } else if (dropY < 0) {
            dropY = 0;
        }

        dom.style.right = dropX + "px";
        dom.style.bottom = dropY + "px";
    };
    document.onmouseup = function () {
        document.onmousemove = null;
        document.onmouseup = null;
    };
};

// 转秒
export const toSecondsFn = (obj: any) => {
    let hour = obj.split(":")[0];
    let min = obj.split(":")[1];
    let sec = obj.split(":")[2];
    return Number(hour * 3600) + Number(min * 60) + Number(sec);
};

// 网盘类型
const mainTypeOption_Network = reactive([
    { name: "全部", val: 6, type: "all" },
    { name: "图片", val: 2, type: "img" },
    { name: "视频", val: 4, type: "video" },
    { name: "音频", val: 3, type: "audio" },
    { name: "文档", val: 1, type: "doc" },
    { name: "文件夹", val: 0, type: "mulv" },
    { name: "其它", val: 5, type: "other" },
]);

// 媒资类型
const mainTypeOption = reactive([
    { name: "全部", val: "0", type: "all" },
    { name: "图片", val: "1", type: "img" },
    { name: "视频", val: "2", type: "video" },
    { name: "音频", val: "3", type: "audio" },
    { name: "文档", val: "4", type: "doc" },
    { name: "文件夹", val: "7", type: "folder" },
    { name: "组图", val: "9", type: "zutu" },
    { name: "其它", val: "6", type: "other" },
]);

// 交易
const buyTypeOption = reactive([
    { name: "全部", val: "0", type: "all" },
    { name: "图片", val: "1", type: "img" },
    { name: "视频", val: "2", type: "video" },
    { name: "音频", val: "3", type: "audio" },
    { name: "文档", val: "4", type: "doc" },
]);

const encodeURI1=(url: string) => {
    return (window.encodeURI(url).replace(/\+/g,'%2B').replace(/\#/g,'%23'));
}
// function encodeURI(url: string) {
//     try {
//         if (url) {
//             if (url.includes("?")) {
//                 let urlObj = new URL(url);
//                 let path = urlObj.origin + urlObj.pathname;
//                 let href = url;
//                 let match = href.match(/\?.*=/g);

//                 if (match) {
//                     let reg = new RegExp("\\" + match[0]);
//                     let index = href.search(reg);

//                     let key = match[0];
//                     let value = href.slice(index + key.length);

//                     return path + key + encodeURIComponent(value);
//                 }
//             } else {
//                 return window.encodeURI(url);
//             }
//         }
//         return url;
//     } catch (err) {
//         console.log(err);
//     }
// }

// export default encodeURI;

// 媒资状态不要 上传人  媒资类型  权限 栏目
export {
    timestampToTimeFn,
    mainTypeOptionFn,
    mainTypeOptionIdFn,
    toTimestampFn,
    toTimestampEndFn,
    toTimestampStartFn,
    filterObj,
    handleRemove,
    searchOption_buy,
    searchOption_company,
    mainTypeOption,
    mainTypeOption_Network,
    BreadCrumb,
    senType,
    searchOption_my,
    searchOption_recycle,
    buyTypeOption,
    timeArr,
    encodeURI1,
};
